package com.hawthorn.redis.controller;

import com.hawthorn.component.exception.BizCode;
import com.hawthorn.component.utils.iassert.AssertMyUtil;
import com.hawthorn.entity.po.SysDeptPO;
import com.hawthorn.redis.service.dept.DeptCacheService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>todo 系统部门缓存</p>
 * @author: andy.ten@tom.com | xukaixing@hotmail.com
 * @created: 2021/12/19 2:25 PM
 * @version v1.0.1
 * @copyright: Copyright (c)  andyten
 */
@Api(tags = {"redis-sysdept"})
@RestController
@RequestMapping("/dept")
@Slf4j
public class DeptCacheController
{
  @Autowired
  private DeptCacheService deptCacheService;

  /**
   * <p>todo 重新加载系统部门</p>
   * @author: andy.ten@tom.com
   * @date: 2021/12/20 8:36 PM
   * @version: 1.0.1
   */
  @ApiOperation(value = "加载->重新初始化系统部门", notes = "重新初始化系统部门")
  @ApiImplicitParams({
  })
  @GetMapping(value = "reloadDept")
  public void reloadDept()
  {
    deptCacheService.init();
  }

  /**
   * <p>todo 根据po重新加载部门</p>
   * @param
   * @return: void
   * @author: fengliye@expservice.com.cn
   * @date: 2022/7/21 11:39
   * @version: 1.0.1
   */
  @ApiOperation(value = "加载->根据po重新加载部门", notes = "根据po重新加载部门")
  @ApiImplicitParams({
  })
  @PostMapping(value = "/updateDept")
  public void updateDept(@RequestBody SysDeptPO sysDeptPO)
  {
    deptCacheService.updateDept(sysDeptPO);
  }

  /**
   * <p>todo 根据po重新加载部门</p>
   * @param
   * @return: void
   * @author: fengliye@expservice.com.cn
   * @date: 2022/7/21 11:39
   * @version: 1.0.1
   */
  @ApiOperation(value = "加载->根据id重新加载部门", notes = "根据id重新加载部门")
  @ApiImplicitParams({
  })
  @PostMapping(value = "/updateDeptById")
  public void updateDeptById(@RequestParam Long deptId)
  {
    AssertMyUtil.notNull(deptId, BizCode.VARIABLE_NOT_EMPTY, "deptId");
    deptCacheService.updateDeptById(deptId);
  }
}
